home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / imc9101.zip / LJTEST1.C < prev    next >
C/C++ Source or Header  |  1991-01-18  |  2KB  |  71 lines

  1. // LJTEST1.C -- Print a graphic image on the LaserJet
  2. //
  3. // If you compile with the macro DOSBIN defined, LJTEST1 will
  4. // set the printer stream for DOS to binary mode. Otherwise,
  5. // only the file will be set to binary mode.
  6.  
  7. #define DOSBIN
  8.  
  9. #ifdef DOSBIN
  10. #include <dos.h>
  11. union REGS regs;
  12. #endif
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <fcntl.h>
  17. #include <io.h>
  18.  
  19. int main(void)
  20.    {
  21.    int i,j;
  22.    
  23.    if (setmode(fileno(stdprn),O_BINARY) == -1)
  24.       {
  25.       puts("Can't set printer to O_BINARY mode");
  26.       exit(EXIT_FAILURE);
  27.       }
  28.  
  29. #ifdef DOSBIN
  30.    regs.x.dx = 0x20;                // Set binary mode
  31.    regs.x.bx = fileno(stdprn);
  32.    regs.x.ax = 0x4401;
  33.    int86(0x21,®s,®s);
  34.    if (regs.x.cflag)
  35.       {
  36.       printf("Error %04xH setting PRN device info",regs.x.ax);
  37.       exit(EXIT_FAILURE);
  38.       }
  39. #endif
  40.  
  41.    // Put LaserJet in 75 dpi Graphics Mode
  42.    fputs("\033*t75R",stdprn);
  43.    
  44.    // Set lef marging of graphics image
  45.    fputs("\033*r0A",stdprn);
  46.    
  47.    // Write a "header line" of A5's
  48.    fputs("\033*b32W",stdprn);
  49.       for (i=0; i<16; i++)
  50.          { fputc(0,stdprn); fputc(0xaa,stdprn); }
  51.  
  52.    // Write 16 rows of 16 bit patterns
  53.    for (i=0; i<256; i+=16)
  54.       {
  55.       fputs("\033*b32W",stdprn);
  56.       for (j=i; j<i+16; j++)
  57.          {
  58.          fputc(0,stdprn);
  59.          fputc(j,stdprn);
  60.          }
  61.       }
  62.    
  63.    // Exit graphics mode on LaserJet
  64.    fputs("\033*rB",stdprn);
  65.  
  66.    // Eject page on LaserJet
  67.    fputc(12,stdprn);
  68.  
  69.    return EXIT_SUCCESS;
  70.    }
  71.